package scoreCard.LivestockJudging3C;

import java.util.ArrayList;

import scoreCard.LivestockJudging3C.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class PostAdapter extends ArrayAdapter<FacebookPost> {

int resource;
	
	public PostAdapter(Context context, int textViewResourceId,
			ArrayList<FacebookPost> objects) {
		super(context, textViewResourceId, objects);
		this.resource = textViewResourceId;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LinearLayout postView;
		FacebookPost post = getItem(position);
		
		if (convertView == null)
		{
			postView = new LinearLayout(getContext());
			String inflater = Context.LAYOUT_INFLATER_SERVICE;
			LayoutInflater vi = (LayoutInflater)getContext().getSystemService(inflater);
			vi.inflate(resource, postView, true);
		} else {
			postView = (LinearLayout)convertView;
		}
		
		TextView name = (TextView)postView.findViewById(R.id.nameonPost);
		name.setText(post.getPosterName());
		TextView message = (TextView)postView.findViewById(R.id.postDetails);
		message.setText(post.getMessage());
		TextView timestamp = (TextView)postView.findViewById(R.id.timeStamp);
		timestamp.setText(post.getTimestamp());
		return postView;
	}
}
